-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
static addr loopin: add support for sweepless sweep batching #844
static addr loopin: add support for sweepless sweep batching #844
Conversation
1f5c270
to
92f540b
Compare
60ff75b
to
ec3070f
Compare
bbff3d0
to
2cbd456
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! It's very cool!
Added several comments.
looprpc/client.proto
Outdated
@@ -1617,7 +1617,7 @@ message ListStaticAddressDepositsRequest { | |||
/* | |||
Filters the list of all stored deposits by deposit state. | |||
*/ | |||
DepositState state_filter = 1; | |||
string state_filter = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Now it is not clear from the schema what are the possible values here. Also it is easy to confuse DepositState and StaticAddressLoopInSwapState.
swapserverrpc/staticaddr.proto
Outdated
message FetchSweeplessSweepTxRequest { | ||
// The swap hash of the swap that the client wants to fetch the sweepless | ||
// sweep tx for. | ||
bytes swap_hash = 1; | ||
} | ||
|
||
message FetchSweeplessSweepTxResponse { | ||
// The address that the server wants to sweep the static address deposits | ||
// to. | ||
string sweep_addr = 1; | ||
|
||
// A map of fee rate to the nonces. | ||
map<uint64, ServerSweeplessSigningInfo> fee_rate_to_nonces = 2; | ||
} | ||
|
||
message ServerSweeplessSigningInfo { | ||
// The nonces that the server used to generate the partial sweepless tx | ||
// sigs. | ||
repeated bytes nonces = 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, this should be removed later, in commit "staticaddr/loopin: remove unused code".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, as this commit changes the functionality of what we do
|
||
// FetchLoopInByHash returns the loop-in swap with the given hash. | ||
FetchLoopInByHash(ctx context.Context, swapHash lntypes.Hash) ( | ||
*StaticAddressLoopIn, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit does not build:
# github.com/lightninglabs/loop/staticaddr/loopin
staticaddr/loopin/actions.go:791:23: undefined: looprpc.FetchSweeplessSweepTxRequest
I think it should include SQL changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, the failure starts with the previous commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I'm changing the proto messages, should I add the changes in fsm/actions etc. to the proto commit?
staticaddr/loopin/manager.go
Outdated
case <-ctx.Done(): | ||
return ctx.Err() | ||
} | ||
} | ||
} | ||
|
||
// notifyNotFinished notifies the server that a swap is not finished by | ||
// sending an empty signature map. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"by sending an empty signature map"
This is a part of API.
I propose to add this to description of PushStaticAddressSweeplessSigsRequest.signing_info.
Also, we can make this more explicit by making a oneof: a map or an error (string). If the swap is not finished or any other error happened during signing, we would send PushStaticAddressSweeplessSigsRequest with an error message instead of a map.
staticaddr/loopin/manager.go
Outdated
|
||
// If the loop-in is not in the Succeeded state we return an | ||
// error. | ||
if loopIn.state != Succeeded { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it also accept FetchSignPushSweeplessSweepTx and SucceededSweeplessSigFailed states?
They are removed in a subsequent commit. Maybe it worth adding them here and removing in commit "staticaddr/loopin: update fsm for server ntfn sigs".
|
||
// We'll now sign for every deposit that is part of the loop-in. | ||
responseMap := make(map[string]*looprpc.ClientSweeplessSigningInfo) | ||
for depositOutpoint, nonce := range req.DepositToNonces { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to factor out the body of this for
to a function.
staticaddr/loopin/manager.go
Outdated
// Check if all the deposits requested are part of the loop-in and | ||
// find them in the requested sweep. | ||
depositToIdxMap := make(map[string]int) | ||
for reqOutpoint := range req.DepositToNonces { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to factor out the body of this for
to a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
staticaddr/loopin/manager.go
Outdated
|
||
for i, txIn := range sweepTx.TxIn { | ||
if txIn.PreviousOutPoint.String() == reqOutpoint { | ||
depositToIdxMap[reqOutpoint] = i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also check that req.DepositToNonces
doesn't include duplicate deposits. We can add a check that depositToIdxMap[reqOutpoint]
does not pre-exist here.
_, err = m.cfg.Server.PushStaticAddressSweeplessSigs( | ||
ctx, &looprpc.PushStaticAddressSweeplessSigsRequest{ | ||
SwapHash: loopIn.SwapHash[:], | ||
Txid: txHash[:], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, server knows txhash already, because it depends on unsigned parts only. Can we remove the field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep it, as the txhash is a unique identifier for the explicit sweep right?
2cbd456
to
985d154
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work @sputn1ck, the client notifications are super nice and will surely be further extended.
I left some nits and potential simplifications. Will test it now.
cmd/loop/staticaddr.go
Outdated
@@ -287,48 +287,9 @@ func listDeposits(ctx *cli.Context) error { | |||
} | |||
defer cleanup() | |||
|
|||
var filterState looprpc.DepositState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this commit to be reverted.
staticaddr/loopin/manager.go
Outdated
// Check if all the deposits requested are part of the loop-in and | ||
// find them in the requested sweep. | ||
depositToIdxMap := make(map[string]int) | ||
for reqOutpoint := range req.DepositToNonces { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
staticaddr/loopin/manager.go
Outdated
Index: prevout.OutputIndex, | ||
}] = &wire.TxOut{ | ||
Value: int64(req.PrevoutInfo[i].Value), | ||
PkScript: req.PrevoutInfo[i].PkScript, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the pkscript the same for all deposits. If so couldn't we just call
loopIn.toPrevOuts(loopIn.Deposits, req.PrevoutInfo[0].PkScript)
44092a7
to
e54ccfd
Compare
985d154
to
86c65c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tAck thanks for the batching preparations!
We should fix the mentioned clean-up of musig sessions, they get auto-cleaned if the signing runs smoothly, and then cleaning fails with the mentioned error. We should only cancel sessions if the signing doesn't take place.
We should also fix the minor issues from the previous review.
|
||
// FetchLoopInByHash returns the loop-in swap with the given hash. | ||
FetchLoopInByHash(ctx context.Context, swapHash lntypes.Hash) ( | ||
*StaticAddressLoopIn, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, the failure starts with the previous commit
e3ec4e5
to
7d50c70
Compare
e54ccfd
to
0d87b69
Compare
This commit adds a new notification to the proto, which is used by the server to request signatures for a deposit of a static loop in.
This commit adds support for the new notification of type NotificationTypeStaticLoopInSweepRequest. This notification is sent when a sweep request is received from the server.
This commit adds the listening for sweep requests from the server. On a sweep request the loopin manager will fetch the loop in from the db, do sanity and safety checks and then sign the psbt for the input and send it back to the server.
This commit updates the loop in FSM to handle the new server based
7d50c70
to
144b62c
Compare
This PR adds support for serverside sweepless sweep batching, by listening for notifications from the server and responding
with the signature.
Only the 8 last commits are for review